package shooter.maps;

import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Transparency;
import java.awt.image.BufferedImage;

/**
 * This class optimizes the displaying of images.
 * 
 * @author Michail Tausch
 */
public class ImageRoutines {
//cool method from internet, perhaps also use for other images
//EDIT: Definitely use for all images
//http://forums.sun.com/thread.jspa?threadID=5343141
	
	/**
	 * Optimizes a image and returns it.
	 */
	public static BufferedImage optimizeImage(BufferedImage img){
		GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); 
		GraphicsConfiguration gc = gd.getDefaultConfiguration();

		boolean istransparent = img.getColorModel().hasAlpha();

		BufferedImage img2 = gc.createCompatibleImage(img.getWidth(), img.getHeight(), istransparent ? Transparency.BITMASK : Transparency.OPAQUE);
		Graphics2D g = img2.createGraphics();
		g.drawImage(img, 0, 0, null);
		g.dispose();

		return img2;
	}
}
